/**
 * @author Pawel Gadecki <pidzama@gmail.com>
 * 
 */
package spwodne;

import java.util.List;
import javax.swing.table.AbstractTableModel;

public class MTKlientow extends AbstractTableModel {

    MTKlientow(List lista) {
        l = lista;
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        return l.size();
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        Object tmp;
        switch (col) {
            case 0: // '\0'

                tmp = ((Klient) l.get(row)).getNr();
                break;

            case 1: // '\001'

                tmp = ((Klient) l.get(row)).getNaz();
                break;

            case 2: // '\002'

                tmp = ((Klient) l.get(row)).getIm();
                break;

            case 3: // '\003'

                tmp = ((Klient) l.get(row)).getPow();
                break;

            case 4: // '\004'

                tmp = ((Klient) l.get(row)).getSumaZostalo();
                break;

            default:
                System.out.println("getValue out of bounds");
                tmp = null;
                break;
        }
        return tmp;
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    public void addRow(Klient klient) {
        l.add(klient);
        fireTableDataChanged();
    }

    public void delRow(int n) {
        l.remove(n);
        fireTableDataChanged();
    }
    private List l;
    private String columnNames[] = {
        "Id", "Nazwisko", "Imie", "Pow. [ha]", "Nale\u017Cno\u015B\u0107 [zl]"
    };
}
